package com.example.java2D;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class StereoImageCreator {
    public static void main(String[] args) {
        try {
            // 加载左眼和右眼的图片
            BufferedImage leftImage = ImageIO.read(new File("path/to/left_image.jpg"));
            BufferedImage rightImage = ImageIO.read(new File("path/to/right_image.jpg"));

            // 创建一个新的图片，其宽度是两张图片宽度之和，高度与原图片一致
            int width = leftImage.getWidth() + rightImage.getWidth();
            int height = leftImage.getHeight();
            BufferedImage stereoImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

            // 将左眼和右眼的图片并排画到新图片上
            Graphics2D g2d = stereoImage.createGraphics();
            g2d.drawImage(leftImage, 0, 0, null);
            g2d.drawImage(rightImage, leftImage.getWidth(), 0, null);
            g2d.dispose();

            // 保存合成后的立体图片
            ImageIO.write(stereoImage, "jpg", new File("path/to/stereo_image.jpg"));

            System.out.println("立体图片合成成功！");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
